package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.OrderShoppingBean;
import com.wnhz.work.jy.bean.ShoppingBean;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by d on 2016/10/24.
 */
public class OrderDetailsAdapter extends BaseAdapter {
    private Context context;
    private List<OrderShoppingBean> orderList;
    private View.OnClickListener listener;
    private int type;

    public OrderDetailsAdapter(Context context, List<OrderShoppingBean> orderList, View.OnClickListener listener) {
        this.context = context;
        this.orderList = orderList;
        this.listener = listener;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    public int getCount() {
        return orderList.size();
    }

    @Override
    public Object getItem(int position) {
        return orderList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        OrderViewHolder viewHolder = new OrderViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.order_item, null);
            viewHolder.iv_img = (ImageView) convertView.findViewById(R.id.iv_img);
            viewHolder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            viewHolder.tv_money = (TextView) convertView.findViewById(R.id.tv_money);
            viewHolder.tv_numbers = (TextView) convertView.findViewById(R.id.tv_numbers);

            viewHolder.pl = (TextView) convertView.findViewById(R.id.pl);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (OrderViewHolder) convertView.getTag();
        }


        if (type == 1){
            x.image().bind(viewHolder.iv_img,orderList.get(position).getPic());
            viewHolder.tv_title.setText(orderList.get(position).getGoodname());
            viewHolder.tv_money.setText("¥" + orderList.get(position).getPrice());
            viewHolder.tv_numbers.setText("x"+orderList.get(position).getNums());
            viewHolder.pl.setOnClickListener(listener);
            viewHolder.pl.setTag(position);
            if ("1".equals(orderList.get(position).getIs_evaluation())){
                viewHolder.pl.setText("已评论");
                viewHolder.pl.setSelected(false);
            }else {
                viewHolder.pl.setText("评论");
                viewHolder.pl.setSelected(true);
            }
            if ("3".equals(orderList.get(position).getState())){
                viewHolder.pl.setVisibility(View.VISIBLE);
            }else {
                viewHolder.pl.setVisibility(View.GONE);
            }
        }else {
            x.image().bind(viewHolder.iv_img,orderList.get(position).getGoodsImg());
            viewHolder.tv_title.setText(orderList.get(position).getGoodsName());
            viewHolder.tv_money.setText("¥" + orderList.get(position).getGoodsPrice());
            viewHolder.tv_numbers.setText("x"+orderList.get(position).getGoodsNums());
            viewHolder.pl.setOnClickListener(listener);
            viewHolder.pl.setTag(position);
            viewHolder.pl.setVisibility(View.GONE);
        }


        //viewHolder.pl.setVisibility(View.VISIBLE);
        return convertView;
    }

    class OrderViewHolder {
        ImageView iv_img;
        TextView tv_title;
        TextView tv_color;
        TextView tv_money;
        TextView tv_numbers;
        TextView pl;
    }
}
